package com.easy.controller;


import com.easy.bean.User;
import com.easy.service.UserService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin//允许跨域访问
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping
    public Result add(@RequestBody User user) {
        Object obj = userService.add(user);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody User user) {
        Object obj = userService.edit(user);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable(name = "id") Integer id) {
        Object obj = userService.del(id);
        return Result.success(obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj = userService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(User user) {
        Object obj = userService.all(user);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, User user) {
        userService.page(page, user);
        return Result.success(page);
    }
}
